package com.wenhao.newcode.huawei;

import java.util.*;

/**
 * @author Wenhao Tong
 * @create 2021-07-13 12:31
 */
public class Solution1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Map<String,Integer> result = new HashMap<>();
        while (scanner.hasNext()) {
            String file = scanner.next();
            String lineNumber = scanner.next();
            if (result.containsKey(file)) {
                result.put(file,result.get(file) + 1);
            } else {
                result.put(file,1);
            }
        }
        PriorityQueue<Map.Entry<String,Integer>> heap = new PriorityQueue<>(8, new Comparator<Map.Entry<String, Integer>>() {
            @Override
            public int compare(Map.Entry<String, Integer> entry1, Map.Entry<String, Integer> entry2) {
                return  entry2.getValue() - entry1.getValue();
            }
        });
        for (Map.Entry<String,Integer> entry : result.entrySet()) {
            heap.add(entry);
        }
        while (heap.size() > 0) {
            Map.Entry<String, Integer> poll = heap.poll();
            String fileName = poll.getKey().substring(poll.getKey().lastIndexOf('\\') + 1);
            int index = fileName.lastIndexOf(' ');
            if (index > 16) {
                fileName = fileName.substring(index - 16);
            }
            System.out.println(fileName + " " + poll.getValue());
        }
    }
}
